package com.dc.modules.test.simple.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dc.commons.query.DcQuery;
import com.dc.commons.service.BaseService;
import com.dc.modules.test.simple.domain.Simple;
import com.dc.modules.test.simple.repository.SimpleRepository;

@Service
public class SimpleService extends BaseService<Simple>{

	@Autowired
	private SimpleRepository simpleRepository;
	
	public Simple saveSimple(Simple simple){
		return simpleRepository.save(simple);
	}
	
	public Simple updateSimple(Simple simple){
		return simpleRepository.save(simple);
	}
	
	@Transactional(readOnly=true)
	public List<Simple> queryAll(){
		return (List<Simple>) simpleRepository.findAll();
	}
	
	public void deleteAll(){
		simpleRepository.deleteAll();
	}
	
	public Page<Simple> queryPage(DcQuery dcQuery){
		return simpleRepository.findAll(dcQuery.buildSpecification(Simple.class), dcQuery.getPageable());
	}
}
